﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Xml;
using System.Windows.Forms;

using OneNoteAddin;
using OneNote = Microsoft.Office.Interop.OneNote;
using Microsoft.Office.OneNote;
using Microsoft.Win32;
using System.IO;

namespace EMRNotes
{
    [Guid("670B64A0-A58F-4eec-8257-19048F289833")]

    public class EMRSearch : IOneNoteAddIn
    {

        public bool OnClick([In] String strActivePageID)
        {
            try
            {
                EMRSearchForm frm = new EMRSearchForm();

                if (frm.ShowDialog() == DialogResult.OK)
                {

                    string patientsFolder = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\Software\\MCD-soft\\OneNoteEMR", "EMRFolderPath", "C:\\Patients\\");
                    string newPatientNotebook = Path.Combine(patientsFolder, frm.EMRFolder);
                    OneNoteNotebook patientNoteboook = OneNoteHierarchy.Current.OpenNotebook(newPatientNotebook, false);
                    OneNoteSection sec = patientNoteboook.OpenSection(Resource1.Profile);
                    OneNote.Application appl = new Microsoft.Office.Interop.OneNote.Application();
                    appl.NavigateTo(patientNoteboook.ObjectId.ToString(), sec.ObjectId.ToString(), false);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, Resource1.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }
 

        public bool OnEvent([In] OneNote.OneNoteAddIn_Event evt, [In] String strParamater)
        {
            return true;
        }
    }
}
